﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.BrowserApp
{
    public class CZEnvironment
    {
        /// <summary>
        /// 承载应用的站点地址
        /// </summary>
        public static string HostUrl { get; set; }
        public static string UserIdentity { get; set; }
        public static string UserAccount { get; set; }
        public static string UserPassword { get; set; }
        public static string Solution { get; set; }

        private static string Version = "V1.1";

        public static string GetPartLibBaseAddress()
        {
            if (string.IsNullOrEmpty(HostUrl))
            {
                return AppDomain.CurrentDomain.BaseDirectory;
            }
            return CZEnvironment.HostUrl;
        }

        public static string GetHostConfigFilePath()
        {
            if (string.IsNullOrEmpty(HostUrl))
            {
                return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.xml");
            }
            return string.Format("{0}{1}", HostUrl, "Config/Host.xml");
        }

        public static string GetSpareHostConfigFilePath()
        {
            return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\host.spare.xml");
        }

        public static string GetPartLibConfigFilePath()
        {
            if (string.IsNullOrEmpty(HostUrl))
            {
                return string.Format("{0}{1}", AppDomain.CurrentDomain.BaseDirectory, "Config\\partlibs.xml");
            }
            return string.Format("{0}{1}", HostUrl, "Config/partlibs.xml");
        }

        /// <summary>
        /// 获取方案的存放目录地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionDirectoryPath(string solution)
        {
            return string.Format("{0}\\Coolzon\\BroswerApp\\{1}\\Solution\\{2}\\",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version, 
                solution);
        }

        /// <summary>
        /// 获得方案的配置文件的地址
        /// </summary>
        /// <param name="solution"></param>
        /// <returns></returns>
        public static string GetSolutionFilePath(string solution)
        {
            return string.Format("{0}\\Coolzon\\BroswerApp\\{1}\\Solution\\{2}\\{2}.xml",
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version, 
                solution);
        }

        /// <summary>
        /// 获取日志目录
        /// </summary>
        /// <returns></returns>
        public static string GetLogDirectory()
        {
            return string.Format("{0}\\Coolzon\\Logs\\BroswerApp\\{1}\\", 
                Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData),
                Version);
        }
    }
}
